package com.htl.exampro.paper.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.htl.exampro.paper.mapper.PaperQuestionMapper;
import com.htl.exampro.paper.pojo.domain.PaperQuestionDO;
import com.htl.exampro.paper.pojo.vo.PaperQuestionVO;
import com.htl.exampro.paper.service.PaperQuestionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 试卷试题关联表 服务实现类
 * </p>
 *
 * @author hehehe
 * @since 2025-05-26
 */
@Service
public class PaperQuestionServiceImpl extends ServiceImpl<PaperQuestionMapper, PaperQuestionDO> implements PaperQuestionService {

    @Override
    public List<PaperQuestionVO> queryQuestionIdsByPaperId(String id) {
        LambdaQueryWrapper<PaperQuestionDO> paperQuestionDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<PaperQuestionDO> paperQuestionDOS = list(paperQuestionDOLambdaQueryWrapper.eq(PaperQuestionDO::getPaperId, id));
        return BeanUtil.copyToList(paperQuestionDOS, PaperQuestionVO.class);
    }

    @Override
    public PaperQuestionVO queryPaperQuestion(String paperId, String questionId) {
        PaperQuestionDO paperQuestionDO = baseMapper.selectOne(Wrappers.lambdaQuery(PaperQuestionDO.class)
                .eq(PaperQuestionDO::getPaperId, paperId)
                .eq(PaperQuestionDO::getQuestionId, questionId));
        return BeanUtil.copyProperties(paperQuestionDO, PaperQuestionVO.class);
    }
}
